import { createRouter, createWebHashHistory, creatyWebHistory, createMemoryHistory } from "vue-router"

//1.声明routers配置，一个routes是一个数组，routes对象里面的基本属性由path和component组成

let routes = [

    {
        path: "/",
        component: () => import("../pages/home/index.vue"),
        name: "/",
        meta: {
            name: '导航首页'
        },
        redirect: "/discover/playlist",
        children: [
            {
                path: 'discover',
                component: () => import('../pages/discover/index.vue'),
                redirect: "/discover/playlist",
                name: "discover",
                meta: {
                    //meta中的属性可以随便添加 
                    name: '发现首页'
                },
                children: [
                    {
                        path: 'playlist',
                        component: () => import("../pages/discover/palylist/index.vue"),
                        name: "palylist",
                        meta: {
                            name: '歌单'
                        }
                    }
                ]
            },
            {
                path: 'mine',
                name: "mine",
                meta: {
                    name: "个人中心"
                },
                component: () => new Promise((resolve,reject)=>{
                    setTimeout(()=>{
                        resolve(import("../pages/mine/index.vue"))
                    },5000)
                })
            },
            {
                props: true,//路由解耦合
                path: 'friend/:id',
                name:"friend",
                meta:{
                    name:"朋友"
                },
                //路由独享钩子，当前路由的前置守卫
                //用法和router.beforEach是一摸一样
                beforEnter(to,from){
                     console.log('beforEnter--to',to);
                     console.log('beforEnter--from',from);
                },
                component: () => import('../pages/friend/index.vue')
            },
        ]
    },
    {
        path: "/login",
        component: () => import("../pages/login/index.vue"),
        name:"login",
        meta:{
            name:'登录页'
        }
    },

]

//2.创建路由
const router = createRouter({
    history: createWebHashHistory("/base"),
    routes
})

//导出路由
export default router